import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push;
const originalReplace = VueRouter.prototype.replace;
//push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
    if (onResolve || onReject)
        return originalPush.call(this, location, onResolve, onReject);
    return originalPush.call(this, location).catch(err => err);
};
//replace
VueRouter.prototype.replace = function push(location, onResolve, onReject) {
    if (onResolve || onReject)
        return originalReplace.call(this, location, onResolve, onReject);
    return originalReplace.call(this, location).catch(err => err);
};

const routes = [
    {
        path: '/',
        redirect: '/Home'
    },
    {
        path: '/Home',
        name: 'Home',
        component: () => import('../views/Home/index.vue'),
    },
    //排行榜
    {
        path: '/TopDetail/:id',
        name: 'TopDetail',
        component: () => import('../views/TopDetail/index.vue')
    },
    //新碟
    {
        path: '/NewAlbum',
        name: 'NewAlbum',
        component: () => import('../views/NewAlbum/index.vue'),
        children: [
            {
                path: '/NewAlbum/AlbumView',
                name: 'AlbumView',
                component: () => import('../views/NewAlbum/AlbumView/index.vue'),
            }
        ]
    },
    //歌单详情
    {
        path: '/RecommendDetail/:id',
        name: 'RecommendDetail',
        component: () => import('../views/RecommendDetail/index.vue')
    },
    //歌单
    {
        path: '/PlayList/:name',
        name: 'PlayList',
        component: () => import('../views/PlayList/index.vue')
    },
    //歌曲详情
    {
        path: '/SongDetail/:id',
        name: 'SongDetail',
        component: () => import('../views/SongDetail/index.vue')
    },
    //专辑详情
    {
        path: '/AlbumDetail/:id',
        name: 'AlbumDetail',
        component: () => import('../views/AlbumDetail/index.vue')
    },
    //mv
    {
        path: '/MvDetail',
        name: 'MvDetail',
        component: () => import('../views/MvDetail/index.vue')
    },
    //节目详情
    {
        path: '/ProgramDetail',
        name: 'ProgramDetail',
        component: () => import('../views/ProgramDetail/index.vue')
    },
    //电台详情
    {
        path: '/DjRadioDetail',
        name: 'DjRadioDetail',
        component: () => import('../views/DjRadioDetail/index.vue')
    },
    {
        path: '/Activity',
        name: 'Activity',
        component: () => import('../views/Activity/index.vue')
    },
    {
        path: '/MyMusic',
        name: 'MyMusic',
        component: () => import('../views/MyMusic/index.vue')
    },
    {
        path: '/Friend',
        name: 'Friend',
        component: () => import('../views/Friend/index.vue')
    },
    //电台
    {
        path: '/DjRadio',
        name: 'DjRadio',
        component: () => import('../views/DjRadio/index.vue'),
        children: [
            {
                path: '/DjRadio/MoreView/:type',
                name: 'MoreView',
                component: () => import('../views/DjRadio/MoreView/index.vue')
            },
            {
                path: '/DjRadio/DjRadioHome',
                name: 'DjRadioHome',
                component: () => import('../views/DjRadio/DjRadioHome/index.vue')
            },
            {
                path: '/DjRadio/DjRadioView',
                name: 'DjRadioView',
                component: () => import('../views/DjRadio/DjRadioView/index.vue')
            }

        ]
    },
    //歌手详情
    {
        path: '/SingerSongDetail/:id',
        name: 'SingerSongDetail',
        component: () => import('../views/SingerSongDetail/index.vue'),
        children: [
            {
                path: '/SingerSongDetail/Album/:id',
                name: 'Album',
                component: () => import('../views/SingerSongDetail/Album/index.vue'),
            },
            {
                path: '/SingerSongDetail/MV/:id',
                name: 'MV',
                component: () => import('../views/SingerSongDetail/MV/index.vue')
            },
            {
                path: '/SingerSongDetail/Introduction/:id',
                name: 'Introduction',
                component: () => import('../views/SingerSongDetail/Introduction/index.vue')
            },
            {
                path: '/SingerSongDetail/Work/:id',
                name: 'Work',
                component: () => import('../views/SingerSongDetail/Work/index.vue')
            },

        ]
    },
    //歌手列表
    {
        path: '/ArtistList',
        name: 'ArtistList',
        component: () => import('../views/ArtistList/index.vue'),
        children: [
            {
                path: '/ArtistList/ArtistView',
                name: 'ArtistView',
                component: () => import('../views/ArtistList/ArtistView/index.vue'),
                children: [
                    {
                        path: '/ArtistView/Signed',
                        name: 'Signed',
                        component: () => import('../views/ArtistList/ArtistView/Signed/index.vue')
                    },

                ]
            },
            {
                path: '/ArtistList/OtherArtistView',
                name: 'OtherArtistView',
                component: () => import('../views/ArtistList/OtherArtistView/index.vue')
            }

        ]
    },
    //用户动态，粉丝，关注
    {
        path: '/User',
        name: 'User',
        component: () => import('../views/UserDetail/User/index.vue'),
        children: [
            {
                path: '/User/Event',
                name: 'Event',
                component: () => import('../views/UserDetail/Event/index.vue')
            },
            {
                path: '/User/Follows',
                name: 'Follows',
                component: () => import('../views/UserDetail/Follows/index.vue')
            },
            {
                path: '/User/Fans',
                name: 'Fans',
                component: () => import('../views/UserDetail/Fans/index.vue')
            },
        ]
    },
    //用户详情
    {
        path: '/UserDetail/:id',
        name: 'UserDetail',
        component: () => import('../views/UserDetail/index.vue'),

        children: [
            {
                path: '/UserDetail/:id/UserDetailView/:type',
                name: 'UserDetailView',
                component: () => import('../views/UserDetail/UserDetailView/index.vue')
            },
        ]
    },
    //用户听歌排名
    {
        path: '/Rank/:id/:type',
        name: 'Rank',
        component: () => import('../views/UserDetail/Rank/index.vue'),
        children: [
            {
                path: '/Rank/:id/:type/View',
                name: 'View',
                component: () => import('../views/UserDetail/Rank/View/index.vue')
            },

        ]
    },
    //搜索
    {
        path: '/Search',
        name: 'Search',
        component: () => import('../views/Search/index.vue'),
        children: [
            {
                path: '/Search/SearchView',
                name: 'SearchView',
                component: () => import('../views/Search/SearchView/index.vue')
            },

        ]
    },
    //我的消息
    {
        path: '/Private',
        name: 'Private',
        component: () => import('../views/Private/index.vue'),
        children: [
            {
                path: '/Private/Msg',
                name: 'Msg',
                component: () => import('../views/Private/Msg/index.vue'),
                children: [
                    {
                        path: '/Private/Msg/MsgView',
                        name: 'MsgView',
                        component: () => import('../views/Private/Msg/MsgView/index.vue'),
                    },
                    {
                        path: '/Private/Msg/MsgHome',
                        name: 'MsgHome',
                        component: () => import('../views/Private/Msg/MsgHome/index.vue'),
                    }
                ]
            },
            {
                path: '/Private/At',
                name: 'At',
                component: () => import('../views/Private/At/index.vue')
            },
            {
                path: '/Private/Notify',
                name: 'Notify',
                component: () => import('../views/Private/Notify/index.vue')
            },
            {
                path: '/Private/Comments',
                name: 'Comments',
                component: () => import('../views/Private/Comment/index.vue')
            },

        ]
    },
    //等级
    {
        path: '/Level',
        name: 'Level',
        component: () => import('../views/Level/index.vue')
    },
    {
        path: '/LevelDetails',
        name: 'LevelDetails',
        component: () => import('../views/Level/LevelDetails/index.vue')
    },
    //个人设置
    {
        path: '/Update',
        name: 'Update',
        component: () => import('../views/Update/index.vue')
    },
    //会员
    {
        path: '/Member',
        name: 'Member',
        component: () => import('../views/Member/index.vue')
    },
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes,
    scrollBehavior(to, from, savedPosition) {
        // return 期望滚动到哪个的位置
        return {x: 0, y: 0}
    }

})
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
    return VueRouterPush.call(this, to).catch(err => err)
}
export default router
